import Pagination from "@/components/pagination";
import { Message } from "element-ui";
const easydate = require("@/untils/easydate");
export default {
  components: {
    Pagination
  },
  props: ["activeName"],
  data() {
    return {
      turnPageObj:{}, // 分页对象
      checkApply: false,
      searchLoading: false,
      total: 10,
      agree: false,
      disagree: false,
      qryCourseByIdObj: {
        title: "", // 课程名称
        smallTitle: "", // 课程说明
        introduce: "", // 课程简介
        courseTime: "", // 时长
        openTime: "", // 日期
        updateTime: "", // 时间
        address: "", // 地点
        num: "", // 人数
        courseDepts: "" // 课程类别
      },
      username: "",
      title: "",
      courseDept: "",
      classId: "",
      tableData: [],
      teacherName: ""
    };
  },
  mounted() {
    let params = {
      title: "",
      username: "",
      courseDept: "",
      page: 1,
      pageSize: 10
    };
    this.qryCoursePCResult(params);
  },
  methods: {
    pageNum(prop){
      this.searchList(prop,10);
    },
    pageSizeNum(prop){
      this.searchList(1,prop);
    },
    initData(row,column){
      return row.flag == 0 ? '不公开' : row.flag == 1 ? '公开' : '暂无';
    },
    handleClose(done) {
      done();
      // this.$confirm("确认关闭？")
      //   .then(_ => {
      //     done();
      //   })
      //   .catch(_ => {});
    },
    searchList(page,pageSize) {
      let { title, username, courseDept, teacherName } = this;
      let params = {
        "teaName": teacherName,
        page,
        pageSize
      };
      this.searchLoading = true;
      this.qryCoursePCResult(params);
      this.turnPageObj = params;
    },
    applyClick(row) {
      // console.log(row);
      let params = {
        id: row.id
      };
      this.classId = row.id;
      this.$get("qryCourseById", params, true).then(res => {
        if (res.success) {
          for(var key in res.data){
            if(key == 'flag'){
              if(res.data[key] == 0){
                res.data[key] = false;
              }else{
                res.data[key] = true;
              }
            }
            if(key == "openTime"){
              res.data.date = easydate(res.data[key]).format('yyyy年MM月dd日 HH:mm').split(' ')[0];
              res.data.time = easydate(res.data[key]).format('yyyy年MM月dd日 HH:mm').split(' ')[1];
            }
            if(key == 'courseDept'){
              if(res.data[key] == 1){
                res.data.courseDept = '公司课程'
              }else {
                res.data.courseDept = '部门课程'
              }
            }
          }
          this.checkApply = true;
          this.qryCourseByIdObj = res.data;
        }
      });
    },
    apply(status) {
      let id = this.classId;
      let url = '';
      let params = {
        id
      };
      if (status == 0) {
        this.disagree = true;
        url = 'refCourse';
      } else {
        this.agree = true;
        url = 'passCourse';
      }
      this.$get(url, params).then(res => {
        if (res.success) {
          Message({
            message: "操作成功",
            type: "success",
            duration: 2000
          });
          if (status == 0) {
            this.disagree = false;
          } else {
            this.agree = false;
          }
          this.checkApply = false;
          this.searchList(1,10);
        }else{
          this.agree = false;
          this.disagree = false;
        }
      });
    },
    qryCoursePCResult(params) {
      this.$post("getEVAResult", params).then(res => {
        if (res.success) {
          let isObjNull = JSON.stringify(res.data);
          if (isObjNull !== "{}") {
            let dataList = res.data.evaEntityList;
            this.total = res.data.totals;
            this.tableData = dataList;
          }
          this.searchLoading = false;
        }
      });
    }
  }
};